package logic

import (
	"context"
	"shenzhou-b/rpc/car"

	"shenzhou-b/api/internal/svc"
	"shenzhou-b/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGoodsLogic {
	return &AddGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddGoodsLogic) AddGoods(req *types.AddGoodsRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	goods, err := l.svcCtx.CarSrv.AddGoods(l.ctx, &car.AddGoodsRequest{
		GoodsName:   req.GoodsName,
		GoodsCover:  req.GoodsCover,
		GoodsPrice:  float32(req.GoodsPrice),
		GoodsStock:  req.GoodsStock,
		GoodsStatus: req.GoodsCover,
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}

	return &types.Response{
		Code: 200,
		Msg:  "发布成功",
		Data: map[string]interface{}{"goods": goods},
	}, nil
}
